import tkinter as tk
import card_manager

# 初始化窗口
def init_window():
    window = tk.Tk()
    window.title("To Do List")
    window.geometry("800x600")
    return window

# 创建列框架
def create_columns(window):
    columns = ["To_Do", "In Progress", "Done"]
    global frames
    frames = {}
    
    for col in columns:
        global frame
        frame = tk.Frame(window, relief=tk.RAISED, borderwidth=1)
        frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        frames[col] = frame
        label = tk.Label(frame, text=col, bg='lightblue', font=('Arial', 12, 'bold'))
        label.pack(fill=tk.X)
    return frames

# 添加卡片按钮
def add_create_button(window, create_card_dialog):
    button = tk.Button(window, text="Create", command=create_card_dialog)
    button.pack()

# 关闭窗口时保存任务
def on_closing(window):
    card_manager.save_tasks()
    window.destroy()

# 主界面初始化
def setup_ui(window):
    frames = create_columns(window)
    add_create_button(window, card_manager.create_card_dialog)
    window.protocol("WM_DELETE_WINDOW", lambda: on_closing(window))
    return frames